from apps.orders.models import Order
import datetime

def rented_house(sd=datetime.datetime.now(), ed=None):

    # if isinstance(sd, str):
    #     ed = datetime.datetime.strptime(ed, '%Y-%m-%d')

    sd = datetime.datetime.date(sd)
    ed = datetime.datetime.date(ed)

    house_list = []

    try:
        orders = Order.objects.filter(status__in=[Order.ORDER_STATUS['WAIT_PAYMENT'],
                                                  Order.ORDER_STATUS['PAID'],
                                                  Order.ORDER_STATUS['COMPLETE']],)

        for order in orders:
            if ed is None:
                if order.begin_date < sd < order.end_date:
                    house_list.append(order.house_id)
            else:
                if sd < order.end_date and ed > order.begin_date:
                    house_list.append(order.house_id)


        return house_list
    except Exception as e:
        print(e)
        return






